package com.ai.sml.util;

import java.util.HashMap;
import java.util.Map;

import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.apache.shiro.crypto.hash.SimpleHash;
/**
 * 用户密码加密码,请勿修改
 *
 */
public class EncryptUtil {
	//同Spring-shrio中credentialsMatcher配置参数一致，上线后不准修改！
	private final static String HASH_ALGORITHM_NAME = "md5";
	private final static int HASH_ITERATIONS = 2;
	
	public static Map<String,String> encrypt(String username,String password){
        String salt = new SecureRandomNumberGenerator().nextBytes().toHex();
        SimpleHash hash = new SimpleHash(HASH_ALGORITHM_NAME, password, username + salt, HASH_ITERATIONS);
        String encodedPassword = hash.toHex();
        Map<String,String> encryptMap = new HashMap<String,String>();
        encryptMap.put("loginCertifCrkey", salt);
        encryptMap.put("userLoginPw", encodedPassword);
        return encryptMap;
	}
	public static Map<String,String> encrypt(String username,String password,String salt){
        SimpleHash hash = new SimpleHash(HASH_ALGORITHM_NAME, password, username + salt, HASH_ITERATIONS);
        String encodedPassword = hash.toHex();
        Map<String,String> encryptMap = new HashMap<String,String>();
        encryptMap.put("loginCertifCrkey", salt);
        encryptMap.put("userLoginPw", encodedPassword);
        return encryptMap;
	}
	public static void main(String[] args) {
		Map<String, String> d = encrypt("test", "123456");
		System.out.println(d);
	}
}
